<?php
require_once("../../../config.inc.php");
$isReloadable = false;
require_once("../../../app/_inc/include.php");
require_once("../_inc/procFunction.php");
require_once("./_inc/layoutFunction.php");

$errMsg = "";
$layout = sxREQ('layout');
if(sxREQ("reqtype") == "save")	{
	$errMsg .= layoutMod();
}
if(sxREQ("reqtype") == "")	{
	$sSQL = "SELECT * FROM layout " .
				"WHERE layout = '".sxREQ('layout')."'";
	$objSDAO->query($sSQL, "layout");
	if (!$row = $objSDAO->fetch("layout")){
		$errMsg .= _t("no layout '%s'",sxREQ('layout'))."<br>";
		$url = $_SESSION[USEROBJ]->getHistory(0, true)."&msg=".urlencode($errMsg);
		serverRedir($url);
	}
	sxRDef("description",$row['description']);
	sxRDef("max_colspan",$row['max_colspan']);
	sxRDef("display_only",$row['display_only']);
	sxRDef("flags",$row['flags']);
	sxRDef("note",$row['note']);
}

$aOpz = array("kMenu"=>'pro.lay', "isReloadable"=>false);
echo(headerHTML($aOpz));
  
echo(bodyHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript">
	function objFrmSave(){
		document.objFrm.submit();
	}
</script>
<?php

echo getSubHeader(substr($layout,0,4),substr($layout,5,4));

//output comandi
$aCmd = array("insMD"=>array("pag"=>"javascript:objFrmSave()",
										"title"=>_t("save"),
										"text"=>_t("save")
										),
					"back"=>array()
					);
echo(commandsHTML($aCmd));	

echo getHtmlForm('objFrm');
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('reqtype','save');
echo getHtmlHidden('layout');

echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" colspan='2'>Layout</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\" width=\"15%\">Name*</td>" .
			"<td class=\"text01\" width=\"85%\">".substr($layout,10)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Description*</td>" .
			"<td class=\"text01\">".getHtmlText('description',80,80)."</td>" .
		"</tr>\n");
$aTypeZ = array('form'=>'form','table-line'=>'table-line');
echo("<tr>" .
			"<td class=\"labl01\">Type*</td>" .
			"<td class=\"text01\">".getHtmlSelect('type', $aTypeZ)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Max colspan*</td>" .
			"<td class=\"text01\">".getHtmlText('max_colspan',3,3)."</td>" .
		"</tr>\n");
$aYN = array('Y'=>'Yes','N'=>'No');
echo("<tr>" .
			"<td class=\"labl01\">Display only</td>" .
			"<td class=\"text01\">".getHtmlRadio('display_only',$aYN)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Flags</td>" .
			"<td class=\"text01\">".getHtmlText('flags',100)."</td>" .
		"</tr>\n");
require "../../_inc/aUpgradeStatus.php";
echo("<tr>" .
			"<td class=\"labl01\">Upgrade status</td>" .
			"<td class=\"text01\">".getHtmlSelect('upgrade_status',$aUpgradeStatus)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Note</td>" .
			"<td class=\"text01\">".getHtmlTextArea('note',100,3)."</td>" .
		"</tr>\n");
echo("</table>");
echo(commandsHTML($aCmd));
echo("</form>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());

function layoutMod(){
	global $objSDAO;
	$errMsg = "";
	if(trim($_REQUEST["description"]) == "")
		$errMsg .= _t("description missing")."<br>";
	if(ereg("[^0-9]",sxRequest("max_colspan")) 
	or intval(sxRequest("max_colspan"))< 1 or intval(sxRequest("max_colspan"))> 20)
		$errMsg .= _t("max colspan not numeric or not between 1-20").".<br>";
	if($errMsg != ""){return $errMsg;}
	$sSQL = "UPDATE " .
			"layout " .
			"SET description='".sxRAS("description")."', " .
			"flags='".sxRAS("flags")."', " .
			"display_only='".sxRAS("display_only")."', " .
			"upgrade_status='".sxRAS("upgrade_status")."', " .
			"max_colspan='".sxRAS("max_colspan")."', " .
			"note='".sxRAS("note")."'" .
			"WHERE layout='".sxRAS("layout")."'";	
	$objSDAO->query($sSQL, "mod");
	$url = $_SESSION[USEROBJ]->getHistory(0, true);
	serverRedir($url);
	return 'abnormal end';
}
